package client;

import swing.FrameManager;
import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;

import javax.swing.*;
import java.io.IOException;

public class Main {

    public static void main(String[] args) {
        //加载服务器地址
        String host = System.getProperty("host", "");
        String port = System.getProperty("port", "");
        if (!host.isEmpty() && !port.isEmpty()) {
            Server.setServerAddress(host, Integer.valueOf(port));
            try {
                System.out.println("服务器（" + host + ":" + port + "）连接中......");
                Server.getServerConnectSocket();
            } catch (IOException e) {
                System.out.println("服务器（" + host + ":" + port + "）连接失败");
                e.printStackTrace();
                return;
            }
        }
        //设置整体UI风格
        loadUiStyle();
        //从登录界面启动
        FrameManager.showLoginFrame();
//        FrameManager.showMainFrame();
    }

    private static void loadUiStyle() {
//        try {
//            //设置整体UI风格为Nimbus
//            for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        try {
            //解决切换输入法导致应用白屏的问题
            System.setProperty("sun.java2d.noddraw", "true");
            //使用BeautyEye开源库对整体UI进行美化
            //https://github.com/JackJiang2011/beautyeye
            org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
            BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.translucencyAppleLike;
            UIManager.put("RootPane.setupButtonVisible", false);
            //关闭窗口在不活动时的半透明效果
            BeautyEyeLNFHelper.translucencyAtFrameInactive = false;
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}
